From c62117c665b9de6198a092e1f72d6c68134cbd51 Mon Sep 17 00:00:00 2001 From: jpfox156 Date: Fri, 25 Feb 2022 23:27:36 +1000 Subject: [PATCH] luci-lua-runtime: Update sys.net.conntrack() to use to conntrack tool Fall through to /usr/sbin/conntrack tool if /proc/net/nf_conntrack is not available. /proc/net/nf_conntrack has been obsoleted in recent kernels (https://cateee.net/lkddb/web-lkddb/NF_CONNTRACK_PROCFS.html). This change enables sys.net.conntrack() to return conntrack information via the /usr/sbin/conntrack tool (if installed) instead. Enables population of the /luci/admin/status/realtime/connections list. Signed-off-by: James Fox [ format using tabs ] Signed-off-by: Paul Donald --- modules/luci-lua-runtime/luasrc/sys.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/luci-lua-runtime/luasrc/sys.lua b/modules/luci-lua-runtime/luasrc/sys.lua index e6eb762e48..2b6048e560 100644 --- a/modules/luci-lua-runtime/luasrc/sys.lua +++ b/modules/luci-lua-runtime/luasrc/sys.lua @@ -279,10 +279,14 @@ function net.host_hints(callback) end function net.conntrack(callback) - local ok, nfct = pcall(io.lines, "/proc/net/nf_conntrack") - if not ok or not nfct then + local ok, fd = pcall(io.open, "/proc/net/nf_conntrack") + if not ok or not fd then + ok, fd = pcall(io.popen, "/usr/sbin/conntrack -L -o extended", "r") + end + if not ok or not fd then return nil end + nfct = fd:lines() local line, connt = nil, (not callback) and { } for line in nfct do -- 2.30.2